.url 抓取測試url
.window 使用window物件
.its 在window底下使用localstorage
import { buildUser } from '../xx';
describe('register a new user', () => {
const user = buildUser();
cy.visit('/')
.findByText(/register/i)
.click()
.findByLobelText(/username/i)
.type(user.username)
.findByLobelText(/password/i)
.type(user.password)
.findByText(/submit/i)
.click()
.url()
.should('eq', 'http://localhost:8080/')
.window()
.its('localhost.token')
.should('be.a', 'string')
.findByTestId('username-display')
.should('have.text', user.username)
});
模擬 http responsive error
cy.server().route({
method: 'POST',
url: 'http://localhost:3000/register',
status: 500,
response: {},
});
模擬request
cy.request({
url: 'http:/localhost:3000/register',
method: 'POST',
body: user,
});
很多重複的指令,可以透過custom commands 去
cy.server().route({
method: 'POST',
url: 'http://localhost:3000/register',
status: 500,
response: {}
})